﻿@{
    ViewBag.Title = "Подробный обзор " + ViewBag.devName;
    var tcpResults = new List<KeyValuePair<String, Domain.NetworkService.ResultStatus>>();
}
<div class="title">
    <h2>
        Подробный обзор &#171;@ViewBag.devName&#187;</h2>
</div>
<div id="mainManagePanel">
    @Html.ActionLink("Управление", "DeviceProperty", "Manage", new { devName = ViewBag.devName }, new { devName = ViewBag.devName })
    @Html.ActionLink("Отчет", "CreateReport", "Report", new { devName = @ViewBag.devName }, new { devName = @ViewBag.devName })
    <a href="javascript:void" onclick="StartAllTests()">Запустить</a>
    <a href="javascript:void" onclick="UpdateAllResult()">Обновить</a>
    @Html.TextBox("DaysAgo", null, new { id = "DaysAgo", placeholder = "Кол-во дней" })
    <div class="validMsg">
        @Html.ValidationMessage("DaysAgo", "Ввод только для чисел от 0 до 365, например: 1, 1.5, 0.2")
    </div>
    <input type="hidden" id="hidDevName" value="@ViewBag.devName" />
</div>
<script type="text/javascript">
    function StartAllTests() {
        var days = document.getElementById("DaysAgo").value;
        var dev = document.getElementById("hidDevName").value;
        var fl = parseFloat(days);
        if (days > 365) {
            days = '> 365';
        }
        var path = '/Manage/StartAllTestsOfRemoteDevice?devName=';
        path += dev;
        if (days != '') {
            path += '&daysAgo=';
            path += days;
        }
        window.location.href = path;
    }
    function UpdateAllResult() {
        var days = document.getElementById("DaysAgo").value;
        var dev = document.getElementById("hidDevName").value;
        var fl = parseFloat(days);
        if (days > 365) {
            days = '> 365';
        }
        var path = '/Survey/SurveyDetailed?devName=';
        path += dev;
        if (days != '') {
            path += '&daysAgo=';
            path += days;
        }
        window.location.href = path;
    }
</script>
@{
    Web.Models.DeviceTestsInfo dti = new Web.Models.DeviceTestsInfo();
    dti.DeviceName = ViewBag.devName;
}
@foreach (var item in dti.testResults)
{
    if (item as Domain.NetworkService.EchoResult != null)
    {
    @MvcHtmlString.Create(ViewBag.EchoGraphicResult)
    <div id="chartContainer" style="width: 80%; height: 250px">
    </div>
        int[] mma = ViewBag.MinMaxAvg;
        
    <div class="blockInDetailed">
        <b>Статистика пакетов</b><br />
        <b>Макс:</b> @mma[0] мс. <b>Мин:</b> @mma[1] мс. <b>Среднее:</b> @mma[2] мс. <b>Потеряно:</b>
        @mma[3] шт.
    </div>
    }

    if (item as Domain.NetworkService.TcpResult != null)
    {
        var tr = item as Domain.NetworkService.TcpResult;
        tcpResults.Add(new KeyValuePair<string, Domain.NetworkService.ResultStatus>(tr.ToString(ToStringFormatArgs.DetailedSurvey), tr.Status));
    }
    if (item as Domain.NetworkService.ResolveResult != null)
    {
        if (item as Domain.NetworkService.ResolveResult != null)
        {
            var rr = item as Domain.NetworkService.ResolveResult;
            IPAddress justForCheck;
            if (!IPAddress.TryParse(rr.HostName, out justForCheck))
            {
    <div class="blockInDetailed">
        Доменное имя
        @rr.HostName
        соответсвует следующим IP адресам
        <ul>
            @foreach (var ip in rr.Ips)
            {
                <li>@ip</li>
            }
        </ul>
    </div>
            }
            else
            {
    <div class="blockInDetailed">
        @rr.VarDateTime
        @Domain.NetworkService.NetworkTestDescription.NS
        Не удалось разрешить IP адрес @rr.Ips.ElementAt(0) в доменное имя.
    </div>
            }
        }
    }


}
@if (tcpResults.Count > 0)
{
    <div class="blockInDetailed">
        <b>Состояние портов сетевых протоколов</b><br />
        <ul>
            @foreach (var tcpResult in tcpResults)
            {
                if (tcpResult.Value == Domain.NetworkService.ResultStatus.Success)
                {
                <li class="Success">@tcpResult.Key</li>
                }
                else
                { 
                <li class="Error">@tcpResult.Key</li>
                }
            }
        </ul>
    </div>
}
@{foreach (var item in dti.testResults)
  {
      if (item as Domain.NetworkService.SnmpResult != null)
      {
          var sr = item as Domain.NetworkService.SnmpResult;
    <div class="blockInDetailed">
        <b>SNMP. Состояние системы</b><br />
        @{ var snmpOutput = new Web.Models.SNMPDetailedOutput(ViewBag.devName, dti); }
        <table class="snmpTable">
            @foreach (var snmpOutputItem in snmpOutput.result)
            {
                <tr>
                    <td>
                        @snmpOutputItem.Key
                    </td>
                    <td>
                        @snmpOutputItem.Value
                    </td>
                </tr>
            }
        </table>
    </div>
            break;
      }
  }
  
}
@{ List<Domain.Entities.ErrorLogs> errorLogs = ViewBag.lstErrors; }
<table class="detailedTable" style="width: 80%;">
    <thead>
        <tr>
            <th>
                Список ошибок
            </th>
        </tr>
    </thead>
    @if (errorLogs.Count > 0)
    {
        foreach (var item in errorLogs)
        {
        <tr>
            <td>
                @item.Date
            </td>
            <td>
                @item.IP
            </td>
            <td>
                @item.Type
            </td>
            <td>
                @item.Infos
            </td>
        </tr>
        }
    }
    else
    { 
        <tr>
            <td>
                За указанный период ошибки не обнаружены.
            </td>
        </tr>
    }
</table>
